//
//  HomeViewController.swift
//  sss
//
//  Created by hrrMac on 2019/9/28.
//  Copyright © 2019 hrrMac. All rights reserved.
//

import UIKit
import Alamofire
import KakaJSON
class HomeViewController: BaseViewController {

    @IBOutlet weak var tableView: UITableView!
    
    var loadingView: LoadingPageView?
    
    let dataArr = ["HTTP封装及其用法","刷新组件用法","按钮回调测试",
                   "viewPagerd测试","弹框视图测试","选择框测试",
                   "viewPagerd测试","九宫格","购物车",
                   "购物车Xib测试","storyBoard测试"]
    
    override func viewDidLoad() {
        super.viewDidLoad()
        title = "Swift"
        configUI()
        
        log("测试打印")
        
        for i in 0..<10 {
            Thread.sleep(forTimeInterval: 0.01)
            logWithTime(i)
        }
        // Do any additional setup after loading the view.
    }

    func configUI(){
        
        getNowTimeStamp()
        print(NAVIGATION_HEIGHT)
        
        print(UIApplication.shared.statusBarFrame.size.height);
        
//        showToast("22", duration: .)
        
//        view.makeToastActivity(.center)
            
        tableView.dataSource = self;
        tableView.delegate = self;
        tableView.register(UITableViewCell.self, forCellReuseIdentifier: "homecell")
        httpRequest()
        
    }
    
    func httpRequest(){
        loadingView = LoadingPageView(view)
        loadingView?.showLoadingPage()
        DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [self] in
            self.loadingView?.dismissLoadingPage()
        }
    }
    
}


extension HomeViewController:UITableViewDataSource,UITableViewDelegate{
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return dataArr.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "homecell", for: indexPath)
        cell.textLabel?.text = dataArr[indexPath.row]
        return cell
    }
    
    
    @objc func dismissMb() {
        mbDismiss()
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    
        let 哈哈 = dataArr[indexPath.row]
        
        if 哈哈 == "弹框视图测试" {
            navigationController?.pushViewController(DialogViewController(), animated: true)
            return
        }
        if 哈哈 == "选择框测试" {
            navigationController?.pushViewController(PickerViewTestViewController(), animated: true)
            return
//
        }
        //
        if 哈哈 == "HTTP封装及其用法" {
            navigationController?.pushViewController(HTTPTestViewController(), animated: true)
            return
        
        }
        
        if 哈哈 == "购物车" {
            navigationController?.pushViewController(ShoppingCarViewController(), animated: true)
            return
        
        }
        if 哈哈 == "购物车Xib测试" {
            navigationController?.pushViewController(ShoppingCarXibTextViewController(), animated: true)
            return
        
        }
        if 哈哈 == "storyBoard测试" {
//            if #available(iOS 13.0, *) {
//                let vc = UIStoryboard(name: "SBTestViewController", bundle: nil).instantiateViewController(identifier: "test")
//            } else {
//                // Fallback on earlier versions
//            }
            
            
            let vc = UIStoryboard(name: "SBTestViewController", bundle: nil).instantiateInitialViewController()
            
            navigationController?.pushViewController(vc!, animated: true)
            return
        
        }
        //测试
        
        
        
        
        
        
        
        
        if indexPath.row == 0 {
//            navigationController?.pushViewController(RefreshViewController.init(), animated: true)
            return
        }
        
        if indexPath.row == 1 {
//            ButtonTestViewController
//            navigationController?.pushViewController(ButtonTestViewController.init(), animated: true)

        }
        if indexPath.row == 2 {
//            navigationController?.pushViewController(ViewPagerTestViewController.init(), animated: true)
        }
        
         if indexPath.row == 2 {
        //            navigationController?.pushViewController(ViewPagerTestViewController.init(), animated: true)
        }
        
    }
    
    
}


class HomeModel: Convertible{
    var avatar:String?
    var comment:String?
    var content: String?
    required init(){}
}


